import request from "@/utils/request";

export function getRole(id) {
  return request({
    url: "/api/identity/roles/" + id,
    method: "get",
  });
}

export function getRoles(paramters) {
  return request({
    url: "/api/identity/roles",
    method: "get",
    params: paramters,
  });
}

export function getAllRoles() {
  return request({
    url: "/api/identity/roles/all",
    method: "get",
  });
}

export function addRole(role) {
  return request({
    url: "/api/identity/roles",
    method: "post",
    data: role,
  });
}

export function deleteRole(id) {
  return request({
    url: "/api/identity/roles/" + id,
    method: "delete",
  });
}

export function getRolePermissions(roleName) {
  let url = `/api/permission-management/permissions?providerKey=${roleName}&providerName=R`;

  return request({
    url: url,
    method: "get",
  });
}

export function updateRolePermissions(permissions, roleName) {
  let url = `/api/permission-management/permissions?providerKey=${roleName}&providerName=R`;

  return request({
    url: url,
    method: "put",
    data: { permissions: permissions },
  });
}
